package com.wiboson.money.DataSource.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by moon on 17/4/28.
 */
public class KLine {
    public Date time;//时间
    public Float beginPrice;//开盘价
    public Float endPrice;//收盘价
    public Float highPrice;//最高价
    public Float lowPrice;//最低价
    public Double VOL;//成交量
    public Float price_change;//价格变动
    public Float p_change;//涨跌幅
    public Float ma5;//5日均价
    public Float ma10;//10日均价
    public Float ma20;//20日均价
    public Double vma5;//5日均量
    public Double vma10;//10日均量
    public Double vma20;//20日均量
    public Float turnover;//换手率

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public Float getBeginPrice() {
        return beginPrice;
    }

    public void setBeginPrice(Float beginPrice) {
        this.beginPrice = beginPrice;
    }

    public Float getEndPrice() {
        return endPrice;
    }

    public void setEndPrice(Float endPrice) {
        this.endPrice = endPrice;
    }

    public Float getHighPrice() {
        return highPrice;
    }

    public void setHighPrice(Float highPrice) {
        this.highPrice = highPrice;
    }

    public Float getLowPrice() {
        return lowPrice;
    }

    public void setLowPrice(Float lowPrice) {
        this.lowPrice = lowPrice;
    }

    public Double getVOL() {
        return VOL;
    }

    public void setVOL(Double VOL) {
        this.VOL = VOL;
    }

    public Float getPrice_change() {
        return price_change;
    }

    public void setPrice_change(Float price_change) {
        this.price_change = price_change;
    }

    public Float getP_change() {
        return p_change;
    }

    public void setP_change(Float p_change) {
        this.p_change = p_change;
    }

    public Float getMa5() {
        return ma5;
    }

    public void setMa5(Float ma5) {
        this.ma5 = ma5;
    }

    public Float getMa10() {
        return ma10;
    }

    public void setMa10(Float ma10) {
        this.ma10 = ma10;
    }

    public Float getMa20() {
        return ma20;
    }

    public void setMa20(Float ma20) {
        this.ma20 = ma20;
    }

    public Double getVma5() {
        return vma5;
    }

    public void setVma5(Double vma5) {
        this.vma5 = vma5;
    }

    public Double getVma10() {
        return vma10;
    }

    public void setVma10(Double vma10) {
        this.vma10 = vma10;
    }

    public Double getVma20() {
        return vma20;
    }

    public void setVma20(Double vma20) {
        this.vma20 = vma20;
    }

    public Float getTurnover() {
        return turnover;
    }

    public void setTurnover(Float turnover) {
        this.turnover = turnover;
    }



    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    public KLine buildByHistory(List data){
        try {
            time = format.parse(data.get(0).toString());
            beginPrice = Float.parseFloat(data.get(1).toString().replace(",",""));
            highPrice = Float.parseFloat(data.get(2).toString().replace(",",""));
            endPrice = Float.parseFloat(data.get(3).toString().replace(",",""));
            lowPrice = Float.parseFloat(data.get(4).toString().replace(",",""));
            VOL = Double.parseDouble(data.get(5).toString().replace(",",""));
            price_change = Float.parseFloat(data.get(6).toString().replace(",",""));
            p_change = Float.parseFloat(data.get(7).toString().replace(",",""));
            ma5 = Float.parseFloat(data.get(8).toString().replace(",",""));
            ma10 = Float.parseFloat(data.get(9).toString().replace(",",""));
            ma20 = Float.parseFloat(data.get(10).toString().replace(",",""));

            vma5 = Double.parseDouble(data.get(11).toString().replace(",",""));
            vma10 = Double.parseDouble(data.get(12).toString().replace(",",""));
            vma20 = Double.parseDouble(data.get(13).toString().replace(",",""));
            return this;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public KLine buildByK(List data){
        try {
            time = format.parse(data.get(0).toString());
            beginPrice = Float.parseFloat(data.get(1).toString());
            highPrice = Float.parseFloat(data.get(2).toString());
            endPrice = Float.parseFloat(data.get(3).toString());
            lowPrice = Float.parseFloat(data.get(4).toString());
            VOL = Double.parseDouble(data.get(5).toString());
            return this;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }



    @Override
    public String toString() {
        return "KLine{" +
                "time=" + format.format(time) +
                ", beginPrice=" + beginPrice +
                ", endPrice=" + endPrice +
                ", highPrice=" + highPrice +
                ", lowPrice=" + lowPrice +
                ", VOL=" + VOL +
                ", price_change=" + price_change +
                ", p_change=" + p_change +
                ", ma5=" + ma5 +
                ", ma10=" + ma10 +
                ", ma20=" + ma20 +
                ", vma5=" + vma5 +
                ", vma10=" + vma10 +
                ", vma20=" + vma20 +
                ", turnover=" + turnover +
                '}';
    }
}
